var StartMainLayer02 = cc.Layer.extend({
	lead:null,
	real:null,
    ctor:function () {
        this._super();
// this.loadTitle();
        this.loadStartButton();
        this.loadStartButtonParticle();
//        this.loadVersion();
        return true;
    },
    loadVersion : function(){
    	var version = new cc.LabelTTF(gg.version, gg.fontName, gg.fontSize);
    	version.setColor(cc.color(0,0,0,0));
    	version.setPosition(980, 25);
    	this.addChild(version);
    },
    loadBack: function(menu){
    	var backItem = new cc.MenuItemImage("#button/back.png","#button/back.png",this.callback,this);
    	menu.addChild(backItem, 1, TAG_CLOSE);
    	backItem.setPosition(984, 40);
    },
    loadStartButton : function(){
        this.lead = new cc.MenuItemImage(
        		"#home_lead1.png",
        		"#home_lead2.png",
            this.callback,this);
        this.lead.setPosition(gg.width * 0.25, gg.height * 0.4);
        
        this.real =  new cc.MenuItemImage(
        		"#home_real1.png",
        		"#home_real2.png",
        		this.callback,this);
        this.real.setPosition(gg.width * 0.75, gg.height * 0.4);
        
        var menu = new cc.Menu();
        this.addChild(menu);
        menu.setPosition(0, 0);
        menu.addChild(this.lead,1,TAG_LEAD);
        menu.addChild(this.real,1,TAG_REAL);
        this.loadBack(menu);
    },
    loadStartButtonParticle : function(){
    	var lead_node = new cc.ParticleSystem(res_start02.follow_p);
    	this.addChild(lead_node);
    	lead_node.setPosition(this.lead.x - this.lead.width / 2, this.lead.y - this.lead.height / 2);
        var action = this.getFollowAction(10, this.lead);
        lead_node.runAction(action);
        
        var real_node = new cc.ParticleSystem(res_start02.follow_p);
        this.addChild(real_node);
        real_node.setPosition(this.real.x - this.real.width / 2, this.real.y - this.real.height / 2);
        var action = this.getFollowAction(10, this.real);
        real_node.runAction(action);
    },
    getFollowAction : function(stretch, node){
        var width = node.width;
        var height = node.height;

        var bezier1 = [cc.p(-stretch, 0), cc.p(-stretch, height), cc.p(0, height)];
        var bezierBy1 = cc.bezierBy(0.6, bezier1);
        var move1 = new cc.moveBy(0.7, cc.p(width, 0));

        var bezier2 = [cc.p(stretch, 0), cc.p(stretch, -height), cc.p(0, -height)];
        var bezierBy2 = cc.bezierBy(0.6, bezier2);
        var move2 = new cc.moveBy(0.7, cc.p(-width, 0));

        var action = cc.sequence(bezierBy1, move1, bezierBy2, move2).repeatForever();
        return action;
    },
    callback:function(pSend){
    	switch(pSend.getTag()){
    		case TAG_LEAD:
	    		cc.log("进入引导模式");
	    		gg.teach_type = TAG_LEAD;
	    		this.runPlay();
	    		break;
    		case TAG_REAL:
	    		cc.log("进入实战模式");
	    		gg.teach_type = TAG_REAL;
	    		this.runPlay();
	    		break;
    		case TAG_CLOSE:
	    		ch.howToGo(OP_TYPE_BACK);
	    		break;
    	}
    },
    runPlay:function(){
    	if(loadResHand.checkLoadFinish(TAG_EXP_02, TAG_LOAD_TYPE_RUN)){
    		$.runScene(new RunScene02());	
    	}  else {
    		cc.LoaderScene.preload(g_resources_run02, function () {
    			$.runScene(new RunScene02());
    		}, this);
    	}
    }
});
